package com.spark.usermusicService.controller;


import com.spark.R;
import com.spark.usermusicService.entity.Music;
import com.spark.usermusicService.entity.MusicList;
import com.spark.usermusicService.service.impl.MusicListServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 歌单中的音乐列表 前端控制器
 * </p>
 *
 * @author wzk
 * @since 2021-07-01
 */
@RestController
@RequestMapping("/usermusicService/musiclist")
@CrossOrigin
public class MusicListController {

    @Autowired
    private MusicListServiceImpl musicListService;

//    @GetMapping("/{playlistId}")
//    public R findAllMusicByPlaylistId(@PathVariable("playlistId") String playlistId) {
//        List<MusicList> musicLists = musicListService.getMusiclistByPlaylistId(playlistId);
//        return R.ok().data("items", musicLists);
//    }

    @GetMapping("/{playlistId}")
    public R findAllMusicByPlaylistId(@PathVariable("playlistId") String playlistId) {
        List<Music> musicLists = musicListService.getMusicDetailsByPlaylistId(playlistId);
        return R.ok().data("items", musicLists);
    }

    @GetMapping("/delete/{musicListId}")
    public R deleteByPlayListId(@PathVariable("musicListId") String musicListId) {
        boolean removeById = musicListService.removeById(musicListId);
        return R.ok();
    }

    @PostMapping("/save")
    public R addMusicList(@RequestBody() MusicList musicList) {
        boolean b = musicListService.save(musicList);
        return R.ok();
    }
}

